#! /bin/sh
# PCP QA Test No. 168
# pmlogmerge shall abort if descriptors non consistent across archives
# pv 933456
#
# Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

_cleanup()
{
    _service pmcd restart 2>&1 | _filter_pcp_restart
    _wait_for_pmcd
    _restore_auto_restart pmcd
    _service pmlogger restart 2>&1 | _filter_pcp_restart
    _wait_for_pmlogger
    rm -f $tmp.*
}

status=0	# success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

# don't need to regenerate config.default with pmlogconf
#
export PMLOGGER_CHECK_SKIP_LOGCONF=yes

# force sample PMDA back to a sane state
_reset()
{
    if ! _service pmcd restart 2>&1; then _exit 1; fi \
    | _filter_pcp_restart
    _wait_for_pmcd || _exit 1
    if ! _service pmlogger restart 2>&1; then _exit 1; fi \
    | _filter_pcp_restart
    _wait_for_pmlogger || _exit 1
}

_filter()
{
    sed -e "s;$tmp;TMP;g"
}

# create second archive and try to merge 'em
_doit()
{
    rm -f $tmp.new.* $tmp.out
    echo "log mandatory on 1sec { sample.dynamic.meta }" \
    | pmlogger -l $tmp.log -s 3 $tmp.new
    pmlogextract $tmp.base $tmp.new $tmp.out 2>&1 \
    | _filter
    if [ -f $tmp.out.0 ]
    then
	echo "Oops ... should not have created an output archive!"
	echo
	echo "=== Original metadata ==="
	pminfo -d -a $tmp.base sample.dynamic.meta.metric
	echo
	echo "=== New metadata ==="
	pminfo -d -a $tmp.new sample.dynamic.meta.metric
	echo
	echo "=== Merged metadata ==="
	pminfo -d -a $tmp.out sample.dynamic.meta.metric
	echo
	echo "=== Dump of output archive ==="
	pmdumplog -dilmst $tmp.out
    fi
}

_reset

echo "Check initial metric set up ..."
pminfo -f sample.dynamic.meta

echo "log mandatory on 1sec { sample.dynamic.meta }" \
| pmlogger -l $tmp.log -s 3 $tmp.base

# real QA test starts here

echo "Change metric type ..."
pmstore sample.dynamic.meta.pmdesc.type 3
_doit
pmstore sample.dynamic.meta.pmdesc.type 0

echo "Change metric indom ..."
pmstore sample.dynamic.meta.pmdesc.indom 42
_doit
pmstore sample.dynamic.meta.pmdesc.indom 4294967295

echo "Change metric semantics ..."
pmstore sample.dynamic.meta.pmdesc.sem 0
_doit
pmstore sample.dynamic.meta.pmdesc.sem 4

echo "Change metric units ..."
pmstore sample.dynamic.meta.pmdesc.units 0
_doit
pmstore sample.dynamic.meta.pmdesc.units 520105984

# success, all done
exit
